package bfh._4_semester.simpleCMS.server;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class MysqlTestConnection {
	public static void main(String[] args) {
		System.out.println("MySQL Connect Example.");
		Connection conn = null;
		
		//localhost
//		String url 		= "jdbc:mysql://localhost:3306/";
//		String dbName 	= "sspaeti_bfhcms";
//		String driver 	= "com.mysql.jdbc.Driver";
//		String userName = "root";
//		String password = ""; 
			
		
		//Webpage - sspaeti.com
		String url      =		"jdbc:mysql://sspaeti.mysql.db.hostpoint.ch:3306/sspaeti_bfhcms";
		String driver   =		"com.mysql.jdbc.Driver";
		String userName =		"sspaeti_bfhcms";
		String password =		"sspaeti_bfhcms";
		//		
		
		try {
			Class.forName(driver).newInstance();
			conn = DriverManager
					.getConnection(url, userName, password);
			System.out.println("Connected to the database");
			
			
	        Statement st = conn.createStatement();
	        ResultSet res = st.executeQuery("SELECT username, password FROM user");
	        while(res.next()){
	            System.out.println("username: " + res.getString("username"));
	            System.out.println("Pw: " + res.getString("password"));
	        }
			
			conn.close();
			System.out.println("Disconnected from database");
		} catch (Exception e) {
			System.out.println("jkljl");
			e.printStackTrace();
		}
		
	}
}

